// 不在校购买医保
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database()

exports.main = async (event, context) => {
  const { account, imageUrls ,resaon} = event.data

  try {
    const repeat = await db.collection("student").where(
      {
        account: account
      }
    ).get();
    if (repeat.data.length == 1) {
      try {
        const up = await db.collection("student").where({
          // college:"计算机科学学院"
          account:account
        }).update({
          data: {
            health_insurance:db.command.push(imageUrls), 
            // health_insurance:[],
            health_insurance_check: 2,
            health_insurance_reason:reason
          }
        })
        return { success: true, message: "上传成功" }
      } catch (error) {
        console.error(error);
        return { success: false, message: "0" + error }
      }
    } else {
      return { success: false, message: "上传失败" }
    }
  } catch (error) {
    return { success: false, message: "1" }
  }
}